package com.woniuxy.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class SimpleDeclare {
    //建立通道
    public static void main(String[] args) throws IOException, TimeoutException {
        //创建连接工厂
        ConnectionFactory connectionFactory=new ConnectionFactory();
        //设置连接工厂信息
        connectionFactory.setHost("127.0.0.1");//可以不设置 默认就是localhost
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");
        //获取连接对象
        Connection connection = connectionFactory.newConnection();
        //建立通道
        Channel channel = connection.createChannel();
        //声明一个队列  当simple1队列已经存在，改变simple1配置后并再去声明simple1队列，会报错！！！！！
        channel.queueDeclare("simple1",false,false,false,null);
        //关闭资源
        channel.close();
        connection.close();
    }
}
